/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Inventario.java
 *
 * Created on 15-ene-2012, 13:54:23
 */
package invsys.Vistas;

import invsys.Controladores.ControlProducto;
import invsys.Modelo.Producto;
import invsys.Utilidades.ManejadorBaseDatos;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Hermanos
 */
public class Inventario extends javax.swing.JDialog{
private static DefaultTableModel dtm = new DefaultTableModel();
private static DefaultTableModel dtm2 = new DefaultTableModel();
private static DefaultTableModel dtm3 = new DefaultTableModel();
private static DefaultTableModel dtm4 = new DefaultTableModel();
    /** Creates new form Inventario */
    public Inventario() {
        
        initComponents();
        this.setLocationRelativeTo(this);
        
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new invsys.Imagenes.Fondo.panel("fondo.jpg");
        TotalProductos = new javax.swing.JTextField();
        ProductosAgotados = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable(dtm);
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable2 = new org.jdesktop.swingx.JXTable(dtm2);
        jScrollPane3 = new javax.swing.JScrollPane();
        jXTable3 = new org.jdesktop.swingx.JXTable(dtm3);
        jScrollPane4 = new javax.swing.JScrollPane();
        jXTable4 = new org.jdesktop.swingx.JXTable(dtm4);
        jButton1 = new javax.swing.JButton();
        ProductosStockMin = new javax.swing.JTextField();
        jPanel2 = new invsys.Imagenes.Fondo.panel("transparente.png");
        cbarticulo = new javax.swing.JComboBox();
        BsucarProducto = new javax.swing.JTextField();
        jcMousePanel1 = new jcMousePanel.jcMousePanel();
        jcMousePanel2 = new jcMousePanel.jcMousePanel();
        Productosenventa = new javax.swing.JTextField();

        setTitle("Inventario");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Inventario", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        TotalProductos.setEditable(false);
        TotalProductos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total Productos", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        ProductosAgotados.setEditable(false);
        ProductosAgotados.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ProductosAgotados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Productos Agotados", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        dtm.addColumn("Codigo");
        dtm.addColumn("Nombre");
        dtm.addColumn("Descripción");
        dtm.addColumn("Cantidad");
        jScrollPane1.setViewportView(jXTable1);

        jTabbedPane1.addTab("Todos", jScrollPane1);

        dtm2.addColumn("Codigo");
        dtm2.addColumn("Nombre");
        dtm2.addColumn("Descripción");
        dtm2.addColumn("Cantidad");
        jScrollPane2.setViewportView(jXTable2);

        jTabbedPane1.addTab("Stock-Minimo", jScrollPane2);

        dtm3.addColumn("Codigo");
        dtm3.addColumn("Nombre");
        dtm3.addColumn("Descripción");
        dtm3.addColumn("Cantidad");
        jScrollPane3.setViewportView(jXTable3);

        jTabbedPane1.addTab("Agotados", jScrollPane3);

        dtm4.addColumn("Codigo");
        dtm4.addColumn("Nombre");
        dtm4.addColumn("Descripción");
        dtm4.addColumn("Cantidad");
        jScrollPane4.setViewportView(jXTable4);

        jTabbedPane1.addTab("En Venta", jScrollPane4);

        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        ProductosStockMin.setEditable(false);
        ProductosStockMin.setBorder(javax.swing.BorderFactory.createTitledBorder("Productos StockMiimo"));
        ProductosStockMin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ProductosStockMinActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar Productos"));

        cbarticulo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre:", "Codigo:" }));
        cbarticulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbarticuloActionPerformed(evt);
            }
        });

        BsucarProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                BsucarProductoKeyReleased(evt);
            }
        });

        jcMousePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/inventario.png"))); // NOI18N

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 70, Short.MAX_VALUE)
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 40, Short.MAX_VALUE)
        );

        jcMousePanel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/buscar.png"))); // NOI18N

        javax.swing.GroupLayout jcMousePanel2Layout = new javax.swing.GroupLayout(jcMousePanel2);
        jcMousePanel2.setLayout(jcMousePanel2Layout);
        jcMousePanel2Layout.setHorizontalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 70, Short.MAX_VALUE)
        );
        jcMousePanel2Layout.setVerticalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 40, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbarticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BsucarProducto, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                .addGap(26, 26, 26)
                .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(113, 113, 113))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbarticulo)
                    .addComponent(BsucarProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jcMousePanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcMousePanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(7, Short.MAX_VALUE))
        );

        Productosenventa.setEditable(false);
        Productosenventa.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        Productosenventa.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Productos En Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(TotalProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(ProductosAgotados, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(Productosenventa, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(ProductosStockMin, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 687, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(30, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TotalProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ProductosStockMin, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Productosenventa, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ProductosAgotados, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       
        this.setVisible(false);
        
    }//GEN-LAST:event_jButton1ActionPerformed

        private void cbarticuloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbarticuloActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbarticuloActionPerformed

    private void ProductosStockMinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ProductosStockMinActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ProductosStockMinActionPerformed

    private void BsucarProductoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BsucarProductoKeyReleased
 if(cbarticulo.getSelectedItem().toString().equals("Codigo:")){
           listaProductoId(BsucarProducto.getText());
           listaProductoIdStockminimo(BsucarProducto.getText());
           listaProductoIdAgotados(BsucarProducto.getText());
           listaProductoIdenVenta(BsucarProducto.getText());
           
           
      }else{
          listaproductonombre(BsucarProducto.getText());
            listaProductonombreStockminimo(BsucarProducto.getText());
           listaProductonombreAgotados(BsucarProducto.getText());
           listaProductonombreenVenta(BsucarProducto.getText());
      }
        
        // TODO add your handling code here:
    }//GEN-LAST:event_BsucarProductoKeyReleased

    /**
     * @param args the command line arguments
     */

      public static void main(String args[]) {
        /* Set the Nimbus look and feel */
     

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Inventario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField BsucarProducto;
    private static javax.swing.JTextField ProductosAgotados;
    private static javax.swing.JTextField ProductosStockMin;
    private static javax.swing.JTextField Productosenventa;
    private static javax.swing.JTextField TotalProductos;
    private javax.swing.JComboBox cbarticulo;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    public static javax.swing.JTabbedPane jTabbedPane1;
    private org.jdesktop.swingx.JXTable jXTable1;
    private org.jdesktop.swingx.JXTable jXTable2;
    private org.jdesktop.swingx.JXTable jXTable3;
    private org.jdesktop.swingx.JXTable jXTable4;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private jcMousePanel.jcMousePanel jcMousePanel2;
    // End of variables declaration//GEN-END:variables

public static void listarTodos(){
        try {
            dtm.setNumRows(0);
            int total = 0;
            ControlProducto.listarProducto();
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                total++;
                Producto p = (Producto) it.next();
                int cant = (int) p.getCantidad();
                String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cant+""};
                dtm.addRow(datos);
            }
            TotalProductos.setText(total+"");
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
}
public static void listarStockMin(){
        try {
            dtm2.setNumRows(0);
            int agotados = 0;
            int stockm = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad!=0");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cant = (int) p.getCantidad();
                int stockmin = (int) p.getStockMin();
                if(cant <= stockmin){
                    
                    stockm++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cant+""};
                    dtm2.addRow(datos);
                }
            }
            
            ProductosStockMin.setText(stockm+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
}
public static void listarAgotados(){
        try {
            dtm3.setNumRows(0);
            int cant = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad=0");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                 cant = (int) p.getCantidad();
                int cantidad = (int) p.getCantidad();
                   if(cant == 0){
                    
                    cant++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm3.addRow(datos);
                      }                      
            }
            ProductosAgotados.setText(dtm3.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
}
public static void listarEnVenta(){
        try {
            dtm4.setNumRows(0);
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE  cantidad!=0");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cantidad = (int) p.getCantidad();
                String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm4.addRow(datos);
                                           
            }
            Productosenventa.setText(dtm4.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
}
private void listaproductonombre(String text) {
        try {
            dtm.setNumRows(0);
            
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProducto.con=mbd.getConexion();
             ControlProducto.listarProducto1("SELECT *FROM productos WHERE nombre LIKE '%"+text+"%'");
             Iterator iter1= ControlProducto.getProducto().iterator()
                     ;
             while(iter1.hasNext()){
                Producto pro = (Producto) iter1.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",can+"", stm+""};
                                 dtm.addRow(fila);  
                             
        
             }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
private void listaProductoId(String text) {
        try {
            dtm.setNumRows(0);
           
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProducto.con=mbd.getConexion();
             ControlProducto.listarProducto1("SELECT *FROM productos WHERE codigo LIKE '%"+text+"%'");
             Iterator iter1= ControlProducto.getProducto().iterator()
                     ;
             while(iter1.hasNext()){
                Producto pro = (Producto) iter1.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getNombre(), pro.getDescripcion(), can+""};
                               dtm.addRow(fila);  
                             
        
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
}
public static void Iniciar() {
        listarTodos();
        listarStockMin();
        listarAgotados();
        listarEnVenta();
    }

    private void listaProductoIdStockminimo(String text) {
               try {
            dtm2.setNumRows(0);
            int agotados = 0;
            int stockm = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad!=0 AND codigo LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cant = (int) p.getCantidad();
                int stockmin = (int) p.getStockMin();
                if(cant <= stockmin){
                    
                    stockm++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cant+""};
                    dtm2.addRow(datos);
                }
            }
            
            ProductosStockMin.setText(stockm+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaProductoIdAgotados(String text) {
              try {
            dtm3.setNumRows(0);
            int cant = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad=0 AND codigo LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                 cant = (int) p.getCantidad();
                int cantidad = (int) p.getCantidad();
                   if(cant == 0){
                    
                    cant++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm3.addRow(datos);
                      }                      
            }
            ProductosAgotados.setText(dtm3.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void listaProductoIdenVenta(String text) {
        try {
            dtm4.setNumRows(0);
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE  cantidad!=0 AND codigo LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cantidad = (int) p.getCantidad();
                String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm4.addRow(datos);
                                           
            }
            Productosenventa.setText(dtm4.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void listaProductonombreStockminimo(String text) {
               try {
            dtm2.setNumRows(0);
            int agotados = 0;
            int stockm = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad!=0 AND nombre LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cant = (int) p.getCantidad();
                int stockmin = (int) p.getStockMin();
                if(cant <= stockmin){
                    
                    stockm++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cant+""};
                    dtm2.addRow(datos);
                }
            }
            
            ProductosStockMin.setText(stockm+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaProductonombreAgotados(String text) {
              try {
            dtm3.setNumRows(0);
            int cant = 0;
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE cantidad<stockmin AND cantidad=0 AND nombre LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                 cant = (int) p.getCantidad();
                int cantidad = (int) p.getCantidad();
                   if(cant == 0){
                    
                    cant++;
                    String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm3.addRow(datos);
                      }                      
            }
            ProductosAgotados.setText(dtm3.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaProductonombreenVenta(String text) {
        try {
            dtm4.setNumRows(0);
            ControlProducto.listarProducto1("SELECT * FROM productos  WHERE  cantidad!=0 AND nombre LIKE '%"+text+"%'");
            Iterator it = ControlProducto.getProducto().iterator();
            while(it.hasNext()){
                Producto p = (Producto) it.next();
                int cantidad = (int) p.getCantidad();
                String[] datos ={p.getCodigo(), p.getNombre(), p.getDescripcion(), cantidad+""};
                    dtm4.addRow(datos);
                                           
            }
            Productosenventa.setText(dtm4.getRowCount()+"");
            
        } catch (SQLException ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Inventario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
